<?php
/**
 * 模块启动文件
 */
namespace addons\good;
use system\Addon;

class Good extends Addon {
    public function getName()
    {
        return 'good';
    }

    public function getVersion()
    {
        return [
            '1.0.0'
        ];
    }

    public function getAuthor()
    {
        return 'Colin';
    }

    public function getDesc()
    {
        return '商品管理、分类管理';
    }

    public function install()
    {
        $sql['1.0.0'] = "CREATE TABLE IF NOT EXISTS `@category`(
id int unsigned not null auto_increment primary key , 
title varchar(40) not null comment '分类名' , 
pid int(0) unsigned null default 0 comment '上级分类' , 
description varchar(200) null comment '描述' , 
image varchar(200) null comment '图片图标' , 
create_time int(10) default 0 comment '添加时间',
key pid(`pid`)
)engine=myisam charset=utf8 comment='分类表';
CREATE TABLE `mc_goods` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) DEFAULT NULL COMMENT '商品名',
  `thumb` varchar(100) DEFAULT NULL COMMENT '缩略图',
  `category_id` varchar(200) DEFAULT '0' COMMENT '所属分类',
  `content` text COMMENT '商品描述',
  `price` decimal(10,2) DEFAULT '0.00' COMMENT '商品价格',
  `stock` int(10) DEFAULT '0' COMMENT '库存',
  `sort` int(11) DEFAULT NULL COMMENT '排序、越大排在前面',
  `state` tinyint(1) DEFAULT NULL COMMENT '状态 1 显示0 隐藏 -1 下架',
  `create_time` int(10) DEFAULT NULL COMMENT '创建时间',
  `update_time` int(10) DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        return $sql;
    }

    public function uninstall()
    {
        $sql['1.0.0'] = "DROP TABLE `@category`;DROP TABLE `@goods`;";
        return $sql;
    }

    public function onInitMenu(&$data = []){
        return [
            [
                'name'  => 'good',
                'title' => '商品管理',
                'icon'  => 'layui-icon-set',
                'list'  => [
                    ['name' => 'category', 'title' => '商品分类', 'auth_name' => 'SysUsers', 'action' => 'index' , 'jump' => '---good/category'],
                    ['name' => 'list', 'title' => '商品列表', 'auth_name' => 'AuthGroup', 'action' => 'index' , 'jump' => '---good/index'],
                ]
            ],
        ];
    }
}